package com.exchange.controller.app.work;

import java.util.List;

import com.exchange.interceptor.BaseValidator;
import com.exchange.interceptor.EnumError;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.upload.UploadFile;

public class WorkOrderValidator extends BaseValidator {
	
	protected void validate(Controller c) {
		setRet(Ret.fail());
    	this.setShortCircuit(true);//短路型验证
    	
    	String url = getActionKey();
		if(url.equals("/app/work/query")) {
			validateInteger("pageNumber", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
		}
		if(url.equals("/app/work/modify")) {
			for(UploadFile file : c.getFiles()) {
        		if(file.getFile().length() > 1048576L*3) {
        			addError("msg", EnumError.img_too_big.getCode());
        		}
        	}
			validateRequiredString("question", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
			validateRequiredString("reason", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
			
		}
		if(url.equals("/app/work/reply")) {
			validateInteger("content", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
			validateInteger("workId", "msg", EnumError.PARAMETER_ARE_MISSING.getCode());
		}
		
		
	}

}
